<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	function mergeArr(arr1,arr2){
		let result = []
		let i = 0,j = 0
		while (i < arr1.length && j < arr2.length){
			if (arr1[i] < arr2[j]){
				result.push(arr1[i])
				i++
			} else {
				result.push(arr2[j])
				j++
			}
		}
		if(i < arr1.length){
			result.push(...arr1.slice(i))
		}
		if (j < arr2.length){
			result.push(...arr2.slice(j))
		}
		return result
	}
	
	// 基础用例
	console.log(mergeArr([1,3,5], [2,4,6]));   // [1,2,3,4,5,6]
	console.log(mergeArr([], [1,2,3]));       // [1,2,3]
	console.log(mergeArr([5,6,7], []));       // [5,6,7]
	
	// 含重复元素
	console.log(mergeArr([1,2,2], [2,3,5]));  // [1,2,2,2,3,5]
	
	// 不同长度数组
	console.log(mergeArr([10,20], [15,25,30,40])); // [10,15,20,25,30,40]
	
	// 负数测试
	console.log(mergeArr([-5,0], [-3,1]));    // [-5,-3,0,1]

</script>
</html>